* Contact variables, family history, demograpics & SES proxies

** Family History and contact variables
gen JordanianRelatives = 1 if  DoyouhaveJordanianrelatives == "Yes"
replace JordanianRelatives = 0 if DoyouhaveJordanianrelatives == "No"
drop DoyouhaveJordanianrelatives

gen SyrianRelatives = 1 if DoyouhaveSyrianrelatives == "Yes"
replace SyrianRelatives = 0 if DoyouhaveSyrianrelatives == "No"
drop DoyouhaveSyrianrelatives

gen PalestinianRoots = 1 if DoyouhavePalestinianroots == "Yes"
replace PalestinianRoots = 0 if DoyouhavePalestinianroots == "No"
drop DoyouhavePalestinianroots

* Distances to Amman according to Google Maps using the provided name & spelling
gen OriginToAmman = 558 if WhichpartofSyriadidyoulive == "Aleppo"
replace OriginToAmman = 207 if WhichpartofSyriadidyoulive == "Damascus"
replace OriginToAmman = 101 if WhichpartofSyriadidyoulive == "Daraa"
replace OriginToAmman = 200 if WhichpartofSyriadidyoulive == "Daraya"
replace OriginToAmman = 200 if WhichpartofSyriadidyoulive == "Daraya"
replace OriginToAmman = 655 if WhichpartofSyriadidyoulive == "Der Zor"
replace OriginToAmman = 207 if WhichpartofSyriadidyoulive == "Eastern Ghouta" // This is Damascus
replace OriginToAmman = 420 if WhichpartofSyriadidyoulive == "Hama"
replace OriginToAmman = 366 if WhichpartofSyriadidyoulive == "Humos"
replace OriginToAmman = 649 if WhichpartofSyriadidyoulive == "Raqqa"
replace OriginToAmman = . if WhichpartofSyriadidyoulive == "Soran"
replace OriginToAmman = 207 if WhichpartofSyriadidyoulive == "Zahira" // This is Damascus

replace OriginToAmman = OriginToAmman / 100
drop WhichpartofSyriadidyoulive

gen TimeInJordan = max(Yearshowlonghaveyoubeenliv,0) + max(Monthshowlonghaveyoubeenli,0)/12 if !(missing(Monthshowlonghaveyoubeenli) & missing(Yearshowlonghaveyoubeenliv))
drop Monthshowlonghaveyoubeenli Yearshowlonghaveyoubeenliv

gen TimeInJordan_long = 1 if TimeInJordan > 8
replace TimeInJordan_long = 0 if missing(TimeInJordan_long) & !missing(TimeInJordan)
replace TimeInJordan = . if TimeInJordan_long

gen NumSyrianFriends = YesDoyouhaveanyfriendswho
replace NumSyrianFriends = 0 if missing(NumSyrianFriends)
gen NumJordanianFriends = AN
replace NumJordanianFriends = 0 if missing(NumJordanianFriends)
gen NumFriendsOutGroup = (Shift=="Morning")*NumSyrianFriends + NumJordanianFriends*(Shift=="Afternoon")
drop YesDoyouhaveanyfriendswho AN
drop NumSyrianFriends NumJordanianFriends

gen FriendsFromOutGroupAtSchool = 1 if Doyouhaveanyfriendsfromthe == "Yes"
replace FriendsFromOutGroupAtSchool = 0 if missing(FriendsFromOutGroupAtSchool)
drop Doyouhaveanyfriendsfromthe

rename Howlonghaveyoubeengoingto TimeGoingToThisSchool

** Demographics & SES proxies
*** Children's Questionnaire
encode Isthechildaboyor, generate(childMale)
replace childMale = 0 if !missing(childMale) & childMale == 2
label define childMale 0 "Female" 1 "Male", replace
drop Isthechildaboyor

label var childMale "Child is a boy (=1)"
	
*** Parents' Questionnaire
egen nChildren = rownonmiss(stChildHowmanychildrendo ndChildHowmanychildrendo rdChildHowmanychildrendo thChildHowmanychildrendo GX GY GZ HA HB HC), strok
replace nChildren = . if stChildHowmanychildrendo == ""
drop stChildHowmanychildrendo ndChildHowmanychildrendo rdChildHowmanychildrendo thChildHowmanychildrendo GX GY GZ HA HB HC HD HE HF HG HH HI HJ HK HL HM

encode Whatisyoursex, generate(parentMale)
replace parentMale = parentMale - 1 if !missing(parentMale)
label define parentMale 0 "Female" 1 "Male", replace
drop Whatisyoursex

/* Income Index 2018
https://globaldatalab.org/shdi/incindex/JOR/?levels=1%2B4&interpolation=0&extrapolation=0&nearest_real=0&years=2018
Aljoun 	0.657
Amman 	0.677
Aqaba 	0.671
Balqa 	0.660
Irbid 	0.658
Jarash 	0.659
Karak 	0.671
Maan 	0.665
Madaba 	0.665
Mafraq 	0.639
Tafiela 	0.669
Zarqa 	0.663 
*/	

encode GovernorateWheredoyoulive, generate(governorateIncome)
replace governorateIncome = 0.657 if governorateIncome == 1 // Ajloun
replace governorateIncome = 0.677 if governorateIncome == 2 // Amman
replace governorateIncome = 0.660 if governorateIncome == 3 // Balqa
replace governorateIncome = 0.658 if governorateIncome == 4 // Irbid
replace governorateIncome = 0.639 if governorateIncome == 5 // Mafraq
replace governorateIncome = 0.663 if governorateIncome == 6 // Russaifa (Zarqa)
drop GovernorateWheredoyoulive

encode Whatisyoureducationallevel, generate(parentEducation)
replace parentEducation = 0 if parentEducation == 5 // Encode does not create a "Group Zero"; Set group with most observations ('Literate but incomplete high school', "Group 5", about 50% of observations) as base group for regressions
replace parentEducation = 2 if parentEducation == 6 // Regroup 'Vocational training' to 'High School' ('Vocational training' has only 6 observations)
replace parentEducation = 2 if parentEducation == 3 // Regroup 'Vocational training' to 'High School' ('Vocational training' has only 6 observations)
label define parentEducation 1 "Bachelor" 2 "High school, vocational training, or higher education " 4 "Illiterate" 0 "Literate but incomplete high school", replace
drop Whatisyoureducationallevel

encode Doyouoryourspousehaveasma, generate(parentsHaveSmartphone)
replace parentsHaveSmartphone = parentsHaveSmartphone - 1 if !missing(parentsHaveSmartphone)
label define parentsHaveSmartphone 0 "No" 1 "Yes", replace
drop Doyouoryourspousehaveasma

encode Doyouhavebooksathome, generate(parentsHaveBooks)
replace parentsHaveBooks = parentsHaveBooks - 1 if !missing(parentsHaveBooks) 
label define parentsHaveBooks 0 "No" 1 "Yes", replace
drop Doyouhavebooksathome

* Have a nice day!